﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="PubSelect.aspx.vb" Inherits="PubProject.PubSelect" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head runat="server">
    <title runat="server" id="mytitle" ></title>
	<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
	<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
	<meta content="JavaScript" name="vs_defaultClientScript">
	<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
	<LINK href="/_grid/map_grid.css" type="text/css" rel="stylesheet">
	<LINK href="/_nav/menu.css" type="text/css" rel="stylesheet">
	<LINK href="/_forms/styles/form.css" type="text/css" rel="stylesheet">
	<LINK href="/_controls/find/find.css" type="text/css" rel="stylesheet">
	<LINK href="/_common/styles/global.css" type="text/css" rel="stylesheet">
	<script language="javascript" src="/_common/scripts/global.js"></script>
	<script language="javascript" src="/_controls/settings.aspx"></script>
	<script language="javascript" src="/_controls/util/util.js"></script>    
    <script  type ="text/javascript">        
        //加载默认值或当前选中值
        window.onload = function()
        {
            var selected = window.dialogArguments;
            var con = document.getElementById("htmlContent");
            var allItems = con.getElementsByTagName("input");
            //全选(默认值失效)
            if (document.getElementById("__all") && __all.value == "1")
            {
                for (var j = 0; j < allItems.length; j++)
                {
                    allItems[j].checked = true;
                }
                return;
            }
            
            //置默认及当前选择
            if (selected)
            {
                for (var i = 0; i < selected.length; i++)
                {
                    for (var j = 0; j < allItems.length; j++)
                    {
                        if (selected[i].toLowerCase() == allItems[j].value.toLowerCase())
                        {
                            allItems[j].checked = true;
                            continue;
                        }
                    }
                }
                setCheckAll();
            }
        }

        function Item(oid,name,level,code)
        {
            this.oid = oid;
            this.name = name;
            this.levelGUID = level;
            this.code = code;
        }
        
        //设置全选是否选中
        function setCheckAll()
        {      
            var con = document.getElementById("htmlContent");
            var allItems = con.getElementsByTagName("input");
            document.getElementById("chkAll").checked = true;
            for (var j = 0; j < allItems.length; j++)
            {
                if (allItems[j].checked == false)
                {
                    document.getElementById("chkAll").checked = false;
                    break;
                }
            }
        }

        //选中项
        function f_checkItem(obj)
        {
            setCheckAll();
        }
        
        //全选或全不选
        function f_checkAll(obj)
        {
            var con = document.getElementById("htmlContent");
            var allItems = con.getElementsByTagName("input");
            var isCheck = document.getElementById("chkAll").checked;
            for (var j = 0; j < allItems.length; j++)
            {
                allItems[j].checked = isCheck;
            }            
        }

        //界面按钮操作
        function f_click(action)
        {
            if (action == "clear")
            {
                window.returnValue = new Array();
                window.close();
            }
            else if (action == "ok")
            {
                var returnValue = new Array();
                var con = document.getElementById("htmlContent");
                var allItems = con.getElementsByTagName("input");
                for (var j = 0; j < allItems.length; j++)
                {
                    if (allItems[j].checked)
                    {
                        returnValue[returnValue.length] = new Item(allItems[j].value, allItems[j].name, allItems[j].levelGUID, allItems[j].code);
                    }
                }
                if (returnValue.length == 0)
                {
                    var type = __type.value.toLowerCase();
                    if (type == "company")
                    {
                        alert("请选择公司!");
                        return;
                    }
                    else if (type == "project")
                    {
                        alert("请选择项目!");
                        return;
                    }
                    else if (type == "product")
                    {
                        alert("请选择产品类型!");
                        return;
                    }
                    else
                    {
                        alert("请选择!")
                        return;
                    }
                }
                window.returnValue = returnValue;
                window.close();                
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <table cellpadding="0" cellspacing ="0" width ="100%" height="100%" style="table-layout:fixed; font-size:9pt; ">
    <colgroup>
        <col width ="15" />
        <col />
        <col width ="15" />
    </colgroup>
        <tr height="6px"><td colspan ="3"></td></tr>
        <tr><td></td>
            <td>
            <div id="htmlContent" style="border:solid 1px #889DC2; background-color:#FFFFFF;height:390px;width:100%; overflow-x:hidden;overflow-y:scroll;">
                <asp:Repeater ID="Repeater1" runat="server" EnableViewState ="false" >
                    <ItemTemplate>
                            <input type="checkbox" id="guid_<%#DataBinder.Eval(Container.DataItem, "guid")%>" oid="<%#DataBinder.Eval(Container.DataItem, "guid")%>" value="<%#DataBinder.Eval(Container.DataItem, "guid")%>" code="<%#DataBinder.Eval(Container.DataItem, "Code")%>"
                            name="<%#DataBinder.Eval(Container.DataItem, "Name")%>" levelGUID="<%#DataBinder.Eval(Container.DataItem, "LevelGUID")%>" onclick="f_checkItem(this)"/>
                        <label for="guid_<%#DataBinder.Eval(Container.DataItem, "guid")%>"><%#DataBinder.Eval(Container.DataItem, "text")%></label><br />
                    </ItemTemplate>
                </asp:Repeater> 
            </div>
            </td>
            <td></td>
        </tr>
        <tr  height="20px"><td colspan ="3">&nbsp;<input type="checkbox" value="all" id="chkAll" runat="server" onclick="f_checkAll(this)" /><label for="chkAll">全选</label></td></tr>
        <tr height="25px">
        <td align ="right" colspan ="3">
        <input id="btnClear" type="button" value="清空" onclick="f_click('clear');" runat="server" visible ="false" style="WIDTH:80px">
        <input id="btnOK" type="button" value="确定" onclick="f_click('ok');" style="WIDTH:80px">
        <input id="btnColse" type="button" value="取消" onclick="window.close()" style="WIDTH:80px">
        </td>
        </tr>
        <tr height="10px"><td colspan ="3"></td></tr>
    </table>
    </form>
</body>
</html>
